package com.atguigu.bigdata.scala.chapter12

import scala.util.matching.Regex

object Scala03_Regex {

    def main(args: Array[String]): Unit = {

        // TODO - 正则表达式
        println(isMobileNumber("18801234567"))
        println(isMobileNumber("11111111111"))
    }
    def isMobileNumber(number: String): Boolean ={
        //val regex = "^((13[0-9])|(14[5,7,9])|(15[^4])|(18[0-9])|(17[0,1,3,5,6,7,8]))[0-9]{8}$".r
        // ((13[0-9]) => 130, 131, 138, 139
        // |
        // (14[5,7,9]) => 145,147,149
        // |
        // (15[^4])    => 151, 152, 153, 155 ~ 159
        // |
        // (18[0-9])   => 181, 182, ...188
        // |
        // (17[0,1,3,5,6,7,8])) =>
        val regex = "^[0-9]{8}$".r
        val length = number.length
        regex.findFirstMatchIn(number.slice(length-11,length)) != None
    }
}
